import axios, { AxiosInstance } from 'axios'
import { type Config, CrawlerFileUtils, getRandomIP, getRandomUserAgent } from '../../utils/baseUtils.js'


type ConfigCanvasPhoto = Config & {
  lastTokenMap:object // 保存上一次的token
  lastPageMap:object // 保存上一次的page
  type:string // 保存类型
}
const fileUtils = new CrawlerFileUtils< ConfigCanvasPhoto >(import.meta.url);
//定义cookis和ja3，都是通过验证所需的必要信息

const axiosInstance: AxiosInstance = axios.create({
    timeout: 10000, // 10秒超时
  })
  axiosInstance.interceptors.request.use((config) => {
    config.headers['User-Agent'] = getRandomUserAgent()
    config.headers['X-Forwarded-For'] = getRandomIP()
    config.headers['X-Real-IP'] = getRandomIP()
    config.headers['Referer'] = 'https://www.canva.cn/'
    return config
  })

export { axiosInstance, fileUtils }